using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class SkeletonOld : Entity
{
    [SerializeField]private float moveSpeed;
    bool isAttacking;
    RaycastHit2D isPlayerDetected;
    [SerializeField] protected float playerCheckDis;
    [SerializeField] protected LayerMask whatIsPlayer;

    protected override void Start()
    {
        base.Start();
    }

    protected override void Update()
    {
        base.Update();

        if (isPlayerDetected)
        {
            if (isPlayerDetected.distance > 1.5f)
            {
                rb.velocity = new Vector2(moveSpeed * faceDir* 3f, rb.velocity.y);
                isAttacking = false;
            }
            else
            {
                isAttacking = true;
  
            }
        }
        

        if (!isGround || isWallDetected)
        {
            Filp();
        }

        if (!isAttacking && !isPlayerDetected)
        {
            rb.velocity = new Vector2(moveSpeed * faceDir, rb.velocity.y);
        }
    }

    protected override void CollisionCheck()
    {
        base.CollisionCheck();
        isPlayerDetected = Physics2D.Raycast(transform.position,Vector2.right,playerCheckDis*faceDir,whatIsPlayer);       
    }

    protected override void OnDrawGizmos()
    {
        base.OnDrawGizmos();
        Gizmos.DrawLine(transform.position, new Vector2(transform.position.x + playerCheckDis, transform.position.y));
    }
}
